package com.bite.friend.controller.exam;

import com.bit.common.security.aspect.NotRequireLogin;
import com.bite.common.core.controller.BaseController;
import com.bite.common.core.domain.R;
import com.bite.common.core.domain.TableDataInfo;
import com.bite.friend.domain.exam.dto.ExamQueryDTO;
import com.bite.friend.domain.exam.dto.ExamRankDTO;
import com.bite.friend.service.exam.IExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/exam")
public class ExamController extends BaseController {

    @Autowired
    private IExamService iExamService;



    /**
     * 查看列表
     * 要返回列表相关信息,总条数,code,msg,不妨定义一个新方法TableDataInfo
     * @param examQueryDTO
     * @return
     */
    @GetMapping("/semiLogin/list")
    public TableDataInfo list(ExamQueryDTO examQueryDTO){
        return getTableDataInfo(iExamService.list(examQueryDTO));
    }



    @NotRequireLogin
    @GetMapping("/semiLogin/redis/list")
    public TableDataInfo redisList(ExamQueryDTO examQueryDTO){
        return iExamService.redisList(examQueryDTO);
    }


    @GetMapping("/rank/list")
    public TableDataInfo rankList(ExamRankDTO examRankDTO){
        return iExamService.rankList(examRankDTO);
    }

    /**
     * 首道题目的id
     * @param examId
     * @return
     */
    @GetMapping("/getFirstQuestion")
    public R<String> getFirstQuestion(Long examId){
        //获取竞赛中题目的顺序-列表,排在第一的返回给前端
        //借鉴上一题那个逻辑
        //每个竞赛都有自己独立的题目列表 key: e:q:l:examId  value:questionId
        return R.ok(iExamService.getFirstQuestion(examId));
    }

    @GetMapping("/preQuestion")
    public R<String> preQuestion(Long examId,Long questionId){
        return R.ok(iExamService.preQuestion(examId,questionId));
    }


    @GetMapping("/nextQuestion")
    public R<String> nextQuestion(Long examId,Long questionId){
        return R.ok(iExamService.nextQuestion(examId,questionId));
    }
}
